package edu.java.lectures.lec07.comparable;

public class Segment implements Comparable<Segment> {

    private int length;

    public Segment(int length) {
	super();
	this.setLength(length);
    }

    public void setLength(int length) {
	this.length = length;
    }

    public int getLength() {
	return length;
    }

    /*
     * if THIS object is "greater" than otherSegment => THIS - OTHER > 0 else if
     * if THIS object is "equals" than otherSegment => THIS - OTHER == 0 else =>
     * THIS object is "smaller" than otherSegment => THIS - OTHER < 0
     */
    @Override
    public int compareTo(Segment otherSegment) {
	if (otherSegment == null) {
	    throw new IllegalArgumentException(
		    "Invalid argument - otherSegment:" + null);
	}
	int myLength = getLength();
	int otherSegmentLength = otherSegment.getLength();

	int result = myLength - otherSegmentLength;
	return result;
    }

    @Override
    public String toString() {
	return length + "";
    }
}
